<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${message("查询组织")}</title>
<link href="/resources/css/common.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/resources/js/reference/jquery.js"></script>
<script type="text/javascript" src="/resources/js/base/dialog.js"></script>
<script type="text/javascript" src="/resources/js/base/request.js"></script>
<script type="text/javascript" src="/resources/js/base/global.js"></script>
<script type="text/javascript" src="/resources/js/reference/mmGrid.js"></script>
<link href="/resources/css/mmGrid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$().ready(function() {
		var cols = [
		{ title:'${message("机构名称")}', name:'name' , align:'left', renderer: function(val,item,rowIndex,obj){
			var grade = item.grade;
			var style_str = 'margin-left: '+(grade*30)+'px;';
			if(item.is_search == 1){
				return '<a href="javascript:void(0);" onClick="parent.change_tab(event,0,\'edit.jhtml?id='+item.id+'&flag=${flag}\')" class="red">'+val+'</a>';
			}else{
				if(obj == undefined){
					if(item.is_leaf == 1){
						return '<span  style="'+style_str+' padding-left:30px"><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='+item.id+'\')" class="red">'+val+'</a></span>';
					}else{
						return '<span style="'+style_str+'" class="treeOpen topNav open" onclick="getChildren(this,event)" data-id="'+item.id+'" data-rowIndex ="'+rowIndex+'" data-status=""></span><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='+item.id+'\')" class="red">'+val+'</a>';
					}	
				}else{
					if(item.is_leaf == 1){
						return '<span  style="'+style_str+' padding-left:30px" class="'+obj+'" ><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='+item.id+'\')" class="red">'+val+'</a></span>';
					}else{
						return '<span style="'+style_str+'" onclick="getChildren(this,event)" class="treeOpen '+obj+'" data-class="'+obj+' id'+item.id+'"  data-id="'+item.id+'" data-rowIndex ="'+rowIndex+'" data-status=""></span><a href="javascript:void(0);" onClick="parent.change_tab(0,\'edit.jhtml?id='+item.id+'\')" class="red">'+val+'</a>';
					}	
				}
			}	
		}},
		{ title:'${message("机构编号")}', name:'sn' , align:'center'},
		{ title:'${message("上级机构")}', name:'tree_path_name' , align:'center'},
	];
	var multiSelect = false;
	[#if multi==2]
		multiSelect = true;
	[/#if]
	
	$mmGrid = $('#table-m1').mmGrid({
		multiSelect:multiSelect,
		autoLoad: true,
		fullWidthRows:true,
		checkByClickTd:true,
		rowCursorPointer:true,
        cols: cols,
        url: 'select_saleOrg_data.jhtml',
        callback:function(){
        	var e=$(".topNav");
        	getChildren(e);
        },
	    params:function(){
        	return $("#listForm").serializeObject();
        },
	    plugins : [
            $('#paginator').mmPaginator()
        ]
    });
	});
	function childMethod(){
	   return $mmGrid.selectedRows();
	};
	function getChildren(e,event){
		var status = $(e).attr("data-status");
		var id = $(e).attr("data-id");
		var rowIndex = $(e).closest("tr").index();
		var oId;
		$idThis= $(".mmGrid").find(".id"+id)
		if(status==""){
			rowIndex = parseInt(rowIndex)+1;
			//console.log(rowIndex)
			$(e).attr("data-status","1");	
			ajaxSubmit($(id),{
				method:'post',
				url:'getChildren.jhtml?id='+id,
				callback: function(data) {
					var uid 
					var item=data.objx;
					if($(e).hasClass("topNav")){
						uid ='id'+$(e).attr("data-id");
					}else{
						uid= $(e).attr("data-class");
					}	
					for(var i=0;i<item.length;i++){
						item[i].parent=id;
					}
					$mmGrid.addRow(item,rowIndex,uid);
					$("tr").removeClass("even");
					$("tr:nth-child(2n)").addClass("even");
				}
			})
			$(e).addClass("treeClose").removeClass("treeOpen")		
		}else if(status==1){
			$idThis.closest("tr").hide();	
			$(e).removeClass("treeClose").addClass("treeOpen")		
			$(e).attr("data-status","0");
			$("tr").removeClass("even");
			$("body").find("tr:visible:even").addClass("even");
		}else{
			$idThis.closest("tr").show();
			oId = $(".mmGrid").find(".id"+id+".treeOpen").attr("data-id")
			$(".mmGrid").find(".id"+oId).closest("tr").hide();		
			$(e).addClass("treeClose").removeClass("treeOpen")
			$(e).attr("data-status","1");
			$("tr").removeClass("even");
			$("body").find("tr:visible:even").addClass("even");
		}
		event.stopPropagation();
	}
</script>
</head>
<body style="min-width: 0px;">
	<form id="listForm" action="select_saleOrg.jhtml" method="get">
		<input type="hidden" name="search" value="1">
			<div class="bar">
				<div class="buttonWrap"></div>
				<div id="searchDiv">
					<div id="search-content">
						<dl>
							<dt>
								<p>${message("机构名称")}：</p>
							</dt>
							<dd>
								<input type="text" class="text" id="name" name="name"
									btn-fun="clear" />
							</dd>
						</dl>
						<dl>
						<dt>
							<p>${message("机构编号")}：</p>
						</dt>
						<dd>
							<input class="text" maxlength="200" type="text"
								name="sn" btn-fun="clear">
						</dd>
					</dl>
					</div>
					<div class="search-btn">
						<a href="javascript:;" id="searchBtn" class="iconButton">${message("1004")}</a>
					</div>
				</div>
			</div>
			<div class="table-responsive">
				<table id="table-m1"></table>
				<div id="body-paginator" style="text-align: left;">
					<div id="paginator"></div>
				</div>
			</div>
	</form>
</body>
</html>